home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Ghost Rocket.lua < prev    next >
Text File  |  2010-09-22  |  5KB  |  142 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Ghost Rocket + Projectile Rocket
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.ghostrocket={}
  10. cc.ghostrocket.rocket={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.ghostrocket.gfx_wpn=loadgfx("weapons/launcher.bmp")                    -- Weapon Image
  14. setmidhandle(cc.ghostrocket.gfx_wpn)
  15. cc.ghostrocket.gfx_pro=loadgfx("weapons/ghostrocket.bmp")                -- Projectile Image
  16. setmidhandle(cc.ghostrocket.gfx_pro)
  17. cc.ghostrocket.sfx_attack=loadsfx("rocketrelease.wav")                    -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Ghost Rocket
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.ghostrocket.id=addweapon("cc.ghostrocket","Ghost Rocket",cc.ghostrocket.gfx_pro,0,2) -- Add Weapon (0 uses, first round 2)
  24.  
  25. function cc.ghostrocket.draw()                                            -- Draw
  26.     setblend(blend_alpha)
  27.     setalpha(1)
  28.     setcolor(220,120,255)
  29.     drawinhand(cc.ghostrocket.gfx_wpn,6,0)
  30.     -- HUD chargebar
  31.     if weapon_charge>0 and weapon_shots==0 then
  32.         hudchargebar(weapon_charge,100)
  33.     end
  34.     -- HUD Crosshair
  35.     if weapon_shots==0 then
  36.         hudcrosshair(6,3)
  37.     end
  38. end
  39.  
  40. function cc.ghostrocket.attack(attack)                                    -- Attack
  41.     if (weapon_shots<=0) then
  42.         -- Charge
  43.         if (attack==1) then
  44.             weapon_charge=weapon_charge+1                                -- Increase charge
  45.         end
  46.         -- Fire a projectile (on release/full charge)
  47.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  48.             -- No more weapon switching!
  49.             useweapon(0)
  50.             playsound(cc.ghostrocket.sfx_attack)
  51.             weapon_shots=weapon_shots+1
  52.             id=createprojectile(cc.ghostrocket.rocket.id)
  53.             projectiles[id]={}
  54.             -- Ignore collision with current player at beginning
  55.             projectiles[id].ignore=playercurrent()
  56.             -- Set initial position of projectile
  57.             projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  58.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  59.             -- Set speed of projectile
  60.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  61.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  62.             -- Effects
  63.             recoil(2)
  64.             -- End Turn
  65.             endturn()
  66.         end
  67.     end
  68. end
  69.  
  70. --------------------------------------------------------------------------------
  71. -- Projectile: Rocket
  72. --------------------------------------------------------------------------------
  73.  
  74. cc.ghostrocket.rocket.id=addprojectile("cc.ghostrocket.rocket")        -- Add Projectile
  75.  
  76. function cc.ghostrocket.rocket.draw(id)                                -- Draw
  77.     -- Setup draw mode
  78.     setblend(blend_alpha)
  79.     setalpha(0.5)
  80.     setcolor(255,255,255)
  81.     setscale(1,1)
  82.     -- Calculate projectile rotation
  83.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  84.     -- Draw projectile
  85.     drawimage(cc.ghostrocket.gfx_pro,projectiles[id].x,projectiles[id].y)
  86.     -- Draw Arrow if out of Screen
  87.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  88. end
  89.  
  90. function cc.ghostrocket.rocket.update(id)                            -- Update
  91.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  92.     -- Particle Tail
  93.     particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  94.     particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  95.     particlefadealpha(0.01)
  96.     particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
  97.     particlecolor(150,0,200+math.random(0,50))
  98.     particlefadealpha(0.04)
  99.     -- Wind + Gravity influence on speed
  100.     projectiles[id].sx=projectiles[id].sx+getwind()
  101.     projectiles[id].sy=projectiles[id].sy+getgravity()
  102.     -- Move (in substep loop for optimal collision precision)
  103.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  104.     msubx=projectiles[id].sx/msubt
  105.     msuby=projectiles[id].sy/msubt
  106.     for i=1,msubt,1 do
  107.         projectiles[id].x=projectiles[id].x+msubx
  108.         projectiles[id].y=projectiles[id].y+msuby
  109.         -- Collision
  110.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3,0,1,1)==1 then
  111.             if playercollision()~=projectiles[id].ignore or objectcollision()>0 then
  112.                 -- Cause damage
  113.                 arealdamage(projectiles[id].x,projectiles[id].y,120,60)
  114.                 -- Destroy terrain
  115.                 terrainexplosion(projectiles[id].x,projectiles[id].y,30,1)
  116.                 -- Crater
  117.                 grey=math.random(0,40)
  118.                 if math.random(0,1)==1 then
  119.                     terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  120.                 else
  121.                     terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  122.                 end
  123.                 -- Free projectile
  124.                 freeprojectile(id)
  125.                 break
  126.             end
  127.         else
  128.             projectiles[id].ignore=0
  129.         end
  130.         -- Water
  131.         if (projectiles[id].y)>getwatery()+5 then
  132.             -- Effects
  133.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  134.             playsound(sfx_hitwater1)
  135.             -- Free projectile
  136.             freeprojectile(id)
  137.             break
  138.         end
  139.     end
  140.     -- Scroll to projectile
  141.     scroll(projectiles[id].x,projectiles[id].y)
  142. end